package demoMod.invincibleOne.patches;

import com.evacipated.cardcrawl.modthespire.lib.SpireInsertPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.evacipated.cardcrawl.modthespire.lib.SpirePrefixPatch;
import com.evacipated.cardcrawl.modthespire.lib.SpireReturn;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import com.megacrit.cardcrawl.relics.MarkOfTheBloom;
import com.megacrit.cardcrawl.rooms.AbstractRoom;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.characters.InvincibleOne;
import demoMod.invincibleOne.relics.AbstractInvincibleRelic;

public class AbstractRelicPatch {
    @SpirePatch(
            clz = AbstractRelic.class,
            method = "obtain"
    )
    @SpirePatch(
            clz = AbstractRelic.class,
            method = "instantObtain",
            paramtypez = {}
    )
    @SpirePatch(
            clz = AbstractRelic.class,
            method = "instantObtain",
            paramtypez = {
                    AbstractPlayer.class,
                    int.class,
                    boolean.class
            }
    )
    public static class PatchObtain {
        public static SpireReturn<Void> Prefix(AbstractRelic relic) {
            if (AbstractDungeon.player instanceof InvincibleOne && !(relic instanceof AbstractInvincibleRelic) &&
                    !relic.relicId.equals(MarkOfTheBloom.ID) && !InvincibleOneMod.isRelicValid) {
                return SpireReturn.Return(null);
            }
            return SpireReturn.Continue();
        }
    }

    @SpirePatch(clz = AbstractRoom.class, method = "spawnRelicAndObtain")
    public static class DontObtainPatch {
        @SpirePrefixPatch
        public static SpireReturn<Void> Prefix(AbstractRoom _instance, float x, float y, AbstractRelic relic) {
            if (AbstractDungeon.player instanceof InvincibleOne && !(relic instanceof AbstractInvincibleRelic) &&
                    !relic.relicId.equals(MarkOfTheBloom.ID) && !InvincibleOneMod.isRelicValid) {
                return SpireReturn.Return(null);
            }
            return SpireReturn.Continue();
        }
    }
}
